package com.example.bigevent.controller;

import com.example.bigevent.pojo.Article;
import com.example.bigevent.pojo.Category;
import com.example.bigevent.pojo.PageBean;
import com.example.bigevent.pojo.Result;
import com.example.bigevent.service.ArticleService;
import com.example.bigevent.utils.JwtUtil;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    //添加文章
   @PostMapping
    public Result add(@RequestBody @Validated(Article.Add.class) Article article){
       articleService.add(article);
       return Result.success();
   }
   //文章列表(条件分页)
   @GetMapping
    public Result<PageBean<Article>> list(Integer pageNum,Integer pageSize
   ,@RequestParam(required = false) String categoryId,@RequestParam(required = false) String state
   )
   {
    return Result.success(articleService.list(pageNum,pageSize,categoryId,state));
   }
   //修改文章
   @PutMapping
    public Result update(@RequestBody @Validated(Article.Update.class) Article article)
   {
        articleService.update(article);
        return Result.success();
   }
   //获取文章详情
    @GetMapping("/detail")
    public Result<Article> detail(Integer id)
    {
        return Result.success(articleService.detail(id));
    }
    //删除文章

    @DeleteMapping
    public Result delete(Integer id)
    {
        articleService.delete(id);
        return Result.success();
    }
}
